/**
 *@description:
 *@file: video_renderer.h
 *@author: snow-tyan
 *@email: zziywang@163.com
 *@date: 8 March 2023
 *@copyright: 2018-2022 AiRiA. All rights reserved.
 */

#pragma once

#include "mygl/util.h"
#include <glm/glm.hpp>
#include <opencv2/opencv.hpp>

namespace mygl {

class Shader;
class Texture2D;

class VideoRenderer {
 public:
  VideoRenderer();
  ~VideoRenderer() = default;

  void Clear();

  void DrawStaticTexture(Shader *shader, Texture2D *texture2d, double fps,
                         glm::vec2 position, glm::vec2 size, bool keep_fps = false);
  void DrawDynamicTexture(Shader *shader, Texture2D *texture2d, uint8_t *data, int width,
                          int height, double fps, glm::vec2 position, glm::vec2 size);
  // TODO: FBO
  void InitFbo(int window_width, int window_height);
  void BeginRender();
  void EndRender(int width, int height);
  void DrawDynamicTextureFbo(Shader *fbo_shader, Shader *screen_shader,
                             Texture2D *texture2d, uint8_t *data, int width, int height,
                             double fps, glm::vec2 position, glm::vec2 size);
  void DrawDynamicBox(Shader *shader, Texture2D *texture2d, uint8_t *data, int width,
                      int height, const HumanBox &box, double fps, glm::vec2 position,
                      glm::vec2 size);
  void DrawDynamicCopy(Shader *shader, Texture2D *texture2d, const cv::Mat &mat,
                       double fps, glm::vec2 position, glm::vec2 size);

 private:
  void initRenderData();
  static HumanBox scaleBox(const HumanBox &box, float scale_x, float scale_y);

 private:
  unsigned int vao_;
  unsigned int vbo_;
  unsigned int ebo_;
  unsigned int fbo_;
  unsigned int fbo_texture_;
};

}  // namespace mygl
